/**
 * 全局样式文件
 * 定义基础样式、重置样式和全局样式
 */

@import './variables.scss';
@import './mixins.scss';

// ==================== CSS Reset ====================

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  padding: 0;
  font-family: $font-family;
  font-size: $font-size-md;
  line-height: $line-height-md;
  color: $text-color;
  background-color: $background-color;
  -webkit-overflow-scrolling: touch;
}

// 重置标题样式
h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-weight: $font-weight-medium;
  line-height: 1.2;
}

h1 { font-size: $font-size-xxl; }
h2 { font-size: $font-size-xl; }
h3 { font-size: $font-size-lg; }
h4 { font-size: $font-size-md; }
h5 { font-size: $font-size-sm; }
h6 { font-size: $font-size-xs; }

// 重置段落样式
p {
  margin: 0;
  line-height: $line-height-md;
}

// 重置列表样式
ul, ol {
  @include reset-list;
}

// 重置链接样式
a {
  color: $primary-color;
  text-decoration: none;
  -webkit-touch-callout: none;
  
  &:active {
    opacity: 0.7;
  }
}

// 重置按钮样式
button {
  @include reset-button;
  font-family: inherit;
  cursor: pointer;
  
  &:disabled {
    cursor: not-allowed;
  }
}

// 重置输入框样式
input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  outline: none;
  -webkit-appearance: none;
  
  &:disabled {
    cursor: not-allowed;
  }
}

// 重置图片样式
img {
  max-width: 100%;
  height: auto;
  vertical-align: middle;
  border: 0;
}

// 重置表格样式
table {
  border-collapse: collapse;
  border-spacing: 0;
}

// 重置表单元素样式
fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  padding: 0;
  border: 0;
}

// ==================== 基础样式类 ====================

// 文本对齐
.text-left { text-align: left; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-justify { text-align: justify; }

// 文本颜色
.text-primary { color: $primary-color; }
.text-success { color: $success-color; }
.text-warning { color: $warning-color; }
.text-danger { color: $danger-color; }
.text-info { color: $info-color; }
.text-muted { color: $text-color-3; }
.text-white { color: $white; }
.text-dark { color: $text-color; }

// 文本大小
.text-xs { font-size: $font-size-xs; }
.text-sm { font-size: $font-size-sm; }
.text-md { font-size: $font-size-md; }
.text-lg { font-size: $font-size-lg; }
.text-xl { font-size: $font-size-xl; }
.text-xxl { font-size: $font-size-xxl; }

// 文本粗细
.text-normal { font-weight: $font-weight-normal; }
.text-medium { font-weight: $font-weight-medium; }
.text-bold { font-weight: $font-weight-bold; }

// 文本省略
.text-ellipsis { @include text-ellipsis(1); }
.text-ellipsis-2 { @include text-ellipsis(2); }
.text-ellipsis-3 { @include text-ellipsis(3); }

// 文本换行
.text-nowrap { white-space: nowrap; }
.text-break { @include text-break; }

// 背景颜色
.bg-primary { background-color: $primary-color; }
.bg-success { background-color: $success-color; }
.bg-warning { background-color: $warning-color; }
.bg-danger { background-color: $danger-color; }
.bg-info { background-color: $info-color; }
.bg-white { background-color: $white; }
.bg-gray { background-color: $gray-1; }
.bg-transparent { background-color: transparent; }

// 边框
.border { border: $border-base; }
.border-top { border-top: $border-base; }
.border-right { border-right: $border-base; }
.border-bottom { border-bottom: $border-base; }
.border-left { border-left: $border-base; }
.border-none { border: none; }

// 圆角
.rounded-none { border-radius: 0; }
.rounded-sm { border-radius: $border-radius-sm; }
.rounded { border-radius: $border-radius-md; }
.rounded-lg { border-radius: $border-radius-lg; }
.rounded-xl { border-radius: $border-radius-xl; }
.rounded-full { border-radius: $border-radius-round; }

// 阴影
.shadow-none { box-shadow: none; }
.shadow-sm { @include box-shadow(light); }
.shadow { @include box-shadow(normal); }
.shadow-lg { @include box-shadow(dark); }

// 显示/隐藏
.show { @include show; }
.hide { @include hide; }
.invisible { visibility: hidden; }
.visible { visibility: visible; }

// 定位
.relative { position: relative; }
.absolute { position: absolute; }
.fixed { position: fixed; }
.sticky { position: sticky; }
.static { position: static; }

// 浮动
.float-left { float: left; }
.float-right { float: right; }
.float-none { float: none; }
.clearfix { @include clearfix; }

// Flex 布局
.flex { display: flex; }
.inline-flex { display: inline-flex; }
.flex-row { flex-direction: row; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-nowrap { flex-wrap: nowrap; }

// Flex 对齐
.justify-start { justify-content: flex-start; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.justify-around { justify-content: space-around; }
.justify-evenly { justify-content: space-evenly; }

.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.items-center { align-items: center; }
.items-baseline { align-items: baseline; }
.items-stretch { align-items: stretch; }

.content-start { align-content: flex-start; }
.content-end { align-content: flex-end; }
.content-center { align-content: center; }
.content-between { align-content: space-between; }
.content-around { align-content: space-around; }
.content-evenly { align-content: space-evenly; }

// Flex 项目
.flex-1 { flex: 1; }
.flex-auto { flex: auto; }
.flex-none { flex: none; }
.flex-grow { flex-grow: 1; }
.flex-shrink { flex-shrink: 1; }

// 间距工具类
@each $size, $value in (
  'xs': $margin-xs,
  'sm': $margin-sm,
  'md': $margin-md,
  'lg': $margin-lg,
  'xl': $margin-xl,
  'xxl': $margin-xxl
) {
  // 外边距
  .m-#{$size} { margin: $value; }
  .mt-#{$size} { margin-top: $value; }
  .mr-#{$size} { margin-right: $value; }
  .mb-#{$size} { margin-bottom: $value; }
  .ml-#{$size} { margin-left: $value; }
  .mx-#{$size} { margin-left: $value; margin-right: $value; }
  .my-#{$size} { margin-top: $value; margin-bottom: $value; }
  
  // 内边距
  .p-#{$size} { padding: $value; }
  .pt-#{$size} { padding-top: $value; }
  .pr-#{$size} { padding-right: $value; }
  .pb-#{$size} { padding-bottom: $value; }
  .pl-#{$size} { padding-left: $value; }
  .px-#{$size} { padding-left: $value; padding-right: $value; }
  .py-#{$size} { padding-top: $value; padding-bottom: $value; }
}

// 零间距
.m-0 { margin: 0; }
.mt-0 { margin-top: 0; }
.mr-0 { margin-right: 0; }
.mb-0 { margin-bottom: 0; }
.ml-0 { margin-left: 0; }
.mx-0 { margin-left: 0; margin-right: 0; }
.my-0 { margin-top: 0; margin-bottom: 0; }

.p-0 { padding: 0; }
.pt-0 { padding-top: 0; }
.pr-0 { padding-right: 0; }
.pb-0 { padding-bottom: 0; }
.pl-0 { padding-left: 0; }
.px-0 { padding-left: 0; padding-right: 0; }
.py-0 { padding-top: 0; padding-bottom: 0; }

// 自动间距
.m-auto { margin: auto; }
.mt-auto { margin-top: auto; }
.mr-auto { margin-right: auto; }
.mb-auto { margin-bottom: auto; }
.ml-auto { margin-left: auto; }
.mx-auto { margin-left: auto; margin-right: auto; }
.my-auto { margin-top: auto; margin-bottom: auto; }

// ==================== 容器样式 ====================

.container {
  width: 100%;
  max-width: $container-max-width;
  margin: 0 auto;
  padding: 0 $container-padding;
}

.container-fluid {
  width: 100%;
  padding: 0 $container-padding;
}

// ==================== 响应式工具类 ====================

// 隐藏/显示工具类
@include respond-to(xs, max) {
  .hidden-xs { display: none !important; }
}

@include respond-to(sm) {
  .hidden-sm-up { display: none !important; }
}

@include respond-to(sm, max) {
  .hidden-sm-down { display: none !important; }
}

@include respond-to(md) {
  .hidden-md-up { display: none !important; }
}

@include respond-to(md, max) {
  .hidden-md-down { display: none !important; }
}

@include respond-to(lg) {
  .hidden-lg-up { display: none !important; }
}

@include respond-to(lg, max) {
  .hidden-lg-down { display: none !important; }
}

// ==================== 动画样式 ====================

// 过渡动画
.transition {
  @include transition();
}

.transition-fast {
  @include transition(all, $animation-duration-fast);
}

.transition-slow {
  @include transition(all, $animation-duration-slow);
}

// 变换
.transform-none { transform: none; }
.scale-50 { transform: scale(0.5); }
.scale-75 { transform: scale(0.75); }
.scale-90 { transform: scale(0.9); }
.scale-95 { transform: scale(0.95); }
.scale-100 { transform: scale(1); }
.scale-105 { transform: scale(1.05); }
.scale-110 { transform: scale(1.1); }
.scale-125 { transform: scale(1.25); }
.scale-150 { transform: scale(1.5); }

.rotate-0 { transform: rotate(0deg); }
.rotate-45 { transform: rotate(45deg); }
.rotate-90 { transform: rotate(90deg); }
.rotate-180 { transform: rotate(180deg); }
.rotate-270 { transform: rotate(270deg); }

// ==================== 滚动条样式 ====================

.scrollbar-thin {
  @include scrollbar(4px);
}

.scrollbar-none {
  scrollbar-width: none;
  -ms-overflow-style: none;
  
  &::-webkit-scrollbar {
    display: none;
  }
}

// ==================== 安全区域适配 ====================

.safe-area-top {
  @include safe-area(padding-top, top);
}

.safe-area-bottom {
  @include safe-area(padding-bottom, bottom);
}

.safe-area-left {
  @include safe-area(padding-left, left);
}

.safe-area-right {
  @include safe-area(padding-right, right);
}

// ==================== 1px 边框 ====================

.hairline {
  @include hairline();
}

.hairline-top {
  @include hairline($border-color, top);
}

.hairline-right {
  @include hairline($border-color, right);
}

.hairline-bottom {
  @include hairline($border-color, bottom);
}

.hairline-left {
  @include hairline($border-color, left);
}

// ==================== 特殊样式 ====================

// 点击态
.clickable {
  cursor: pointer;
  user-select: none;
  -webkit-touch-callout: none;
  
  &:active {
    opacity: 0.7;
  }
}

// 禁用态
.disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

// 加载态
.loading {
  pointer-events: none;
  opacity: 0.7;
}

// 选中态
.selected {
  background-color: $primary-color;
  color: $white;
}

// 高亮态
.highlight {
  background-color: rgba($primary-color, 0.1);
}

// 错误态
.error {
  color: $danger-color;
  border-color: $danger-color;
}

// 成功态
.success {
  color: $success-color;
  border-color: $success-color;
}

// 警告态
.warning {
  color: $warning-color;
  border-color: $warning-color;
}

// ==================== 打印样式 ====================

@media print {
  *,
  *::before,
  *::after {
    background: transparent !important;
    color: #000 !important;
    box-shadow: none !important;
    text-shadow: none !important;
  }
  
  a,
  a:visited {
    text-decoration: underline;
  }
  
  a[href]::after {
    content: " (" attr(href) ")";
  }
  
  abbr[title]::after {
    content: " (" attr(title) ")";
  }
  
  pre,
  blockquote {
    border: 1px solid #999;
    page-break-inside: avoid;
  }
  
  thead {
    display: table-header-group;
  }
  
  tr,
  img {
    page-break-inside: avoid;
  }
  
  img {
    max-width: 100% !important;
  }
  
  p,
  h2,
  h3 {
    orphans: 3;
    widows: 3;
  }
  
  h2,
  h3 {
    page-break-after: avoid;
  }
}